<?php
require_once "functions.php";
$paperId = $_GET['paper_id'];
//connect to the database
//arrange the versions and get the latest version
$result = mysql_query("SELECT `version_id` FROM `version` WHERE `paper_id`= $paperId ORDER BY version_id DESC");
$row = mysql_fetch_assoc($result);
$LatestV = $row['version_id'];
//get the path of the latest version
$query = "SELECT path FROM `version` Where version.paper_id = $paperId AND version.version_id=$LatestV;";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$path = $row ['path'];
//download the pdf
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename= $path");
readfile($path);
?>